package cac.fenjian.resource.system.controller;

import cac.fenjian.resource.system.service.SystemDbService;
import com.cac.dme.adapter.rest.msg.ResponseMsg;
import oracle.jdbc.proxy.annotation.Post;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RequestMapping("system/db")
@RestController
public class SystemDBController {
    @Autowired
    private SystemDbService systemDbService;
    //保存角色信息
    @PostMapping("saveRole")
    public ResponseMsg saveRole(@RequestBody HashMap map){
        return systemDbService.saveRole(map);
    }
    //保存菜单权限信息
    @PostMapping("saveMenuRole")
    public ResponseMsg saveMenuRole(@RequestBody HashMap map){
        List<String> menus = (List<String>) map.get("menus");
        HashMap role = (HashMap) map.get("role");
        return systemDbService.saveMenuRole(menus,role);
    }
    //删除角色信息
    @PostMapping("delRole")
    public ResponseMsg delRole(@RequestBody HashMap role){
        return systemDbService.delRole(role);
    }

    //新增用户
    @PostMapping("saveUser")
    public ResponseMsg saveUser(@RequestBody HashMap map){
        ResponseMsg responseMsg = new ResponseMsg();
        String account = (String) map.get("account");
        String password = (String) map.get("password");
        systemDbService.addUser(account,password);
        return responseMsg;
    }
    //删除用户
    @PostMapping("delUser")
    public ResponseMsg delUser(@RequestBody List<HashMap> map){
        ResponseMsg responseMsg = new ResponseMsg();
        for(int i=0;i<map.size();i++){
            HashMap hashMap = map.get(i);
            String id = (String) hashMap.get("id");
            systemDbService.delUser(id);
        }
        return responseMsg;
    }
    @PostMapping("insertUserRoleBatch")
    public ResponseMsg insertUserRoleBatch(@RequestBody List<HashMap> userroles){
        return systemDbService.insertUserRoleBatch(userroles);
    }

    @PostMapping("delRoleUser")
    public ResponseMsg delRoleUser(@RequestBody List<HashMap> users){
        return systemDbService.delRoleUser(users);
    }
}
